package com.nf.controller.manage;

import com.google.gson.Gson;
import com.nf.controller.BaseServlet;
import com.nf.dao.HallInfoDao;
import com.nf.dao.impl.HallInfoDaoImpl;
import com.nf.util.GsonUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Map;

/**
 * 编写servlet，实现根据影厅Id 删除影厅
 */
@WebServlet("/api/HallDeleteServlet.do")
public class HallDeleteServlet extends BaseServlet {
    @Override
    protected void doDelete(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        BufferedReader reader= req.getReader();
        String str=null;
        String jsonParams="";
        while ((str=reader.readLine())!=null){
            jsonParams=jsonParams+str;
        }
        Map<String,String> map= GsonUtil.parseMap(jsonParams);

        int id= Integer.parseInt(map.get("hallId"));
        HallInfoDao dao=new HallInfoDaoImpl();

        resp.setContentType("application/json;charset=utf-8");
        PrintWriter out = resp.getWriter();
        int r= dao.del(id);
        if(r==1){
            out.print(new Gson().toJson(successJson("删除成功")));
        }else {
            out.print(new Gson().toJson(errorJson("删除失败")));
        }
        out.flush();
        out.close();

    }
}
